import React, {useState, useRef} from 'react'
import {message, Switch} from 'antd'

/**
 * 状态组件操作
 */
const RoleSwitch: React.FC<{ row: { [key: string]: any } }> = (props) => {

  const [loading, setLoading] = useState<boolean>(false)
  const [checked, setChecked] = useState<number>(props.row.status)

  const toggle = async () => {
    try {
      setLoading(true);
      let params: { [key: string]: any } = {}
      params.jobId = props.row.jobId;
      params.status = checked == 1 ? 0 : 1
      // const {code, msg} = await changeStatus(params);
      //
      // if (code != 200) {
      //   return message.error(msg);
      // }
      //
      // setChecked(!checked)
      // return message.success(msg);
    } catch (e) {
      console.error(e)
    } finally {
      setLoading(false);
    }
  };

  return (
    <Switch
      loading={loading}
      onClick={toggle}
      // checked={checked}
    />
  )
}

export default RoleSwitch
